$(function () {
    // 一开始就执行
    getAddress();
    
})

function getAddress() {
    $.ajax({
        url: "/address/getAddress",
        type: "get",
        success: function (jsonArr) {
            for (address of jsonArr.data) {
                let $div;
                if (address.isDefault===1){
                $div = `
                           <div class="user-address active" onclick="checkAddress(this)">
                                <input type="text" name="addressId" value="${address.id}" hidden />
                                <span class="user">${address.receiverName}</span>
                                <span class="address-detail">
                                    ${address.provinceName}
                                    ${address.cityName}
                                    ${address.areaName}
                                    ${address.streetName}
                                    ${address.villageName}
                                    ${address.detail}
                                </span>
                           </div>
                    `; }
                else {
                    $div = `
                           <div class="user-address" onclick="checkAddress(this)">
                                <input type="text" name="addressId" value="${address.id}" hidden />
                                <span class="user">${address.receiverName}</span>
                                <span class="address-detail">
                                    ${address.provinceName}
                                    ${address.cityName}
                                    ${address.areaName}
                                    ${address.streetName}
                                    ${address.villageName}
                                    ${address.detail}
                                </span>
                           </div>
                    `; }
                $("#address").append($div);
            }
        }
    })
}